#include <cstring>

#include <sys/types.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <arpa/inet.h>

#include "UdpClinet.hpp"
#include "Common.hpp"

int main(int argc, char *argv[])
{
    if(argc != 3){
        // LOG(LogLevel::FATAL) 
        std::cerr << "Usage: " << argv[0] << " serverIP serverPORT" << std::endl;
        Die(err::USE_ERR);
    }

    std::string svrIp = argv[1];
    uint16_t svrPort = std::stoi(argv[2]);

    int sockfd = socket(AF_INET, SOCK_DGRAM, 0);
    if(sockfd < 0)
    {
        std::cerr << "socket error" << std::endl;
        Die(err::SOCK_ERR);
    }
    struct sockaddr_in server;
    memset(&server, 0, sizeof(server));
    server.sin_family = AF_INET;
    server.sin_port = ::htons(svrPort);
    server.sin_addr.s_addr = ::inet_addr(svrIp.c_str());

    while(true)
    {
        std::cout << "Please Enter# ";
        std::string msg;
        std::getline(std::cin, msg);
        int n = ::sendto(sockfd, msg.c_str(), msg.size(), 0, CONV(&server), sizeof(server));
        


    }

    return 0;
}